﻿//-----------------------------------------------------------------------
// <copyright file="DeleteMessagesDataResult.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.DomainObjects.ResultData
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;

    /// <summary>
    /// Defines an event that receives a DeleteMessagesDataResult
    /// </summary>
    /// <param name="dataResult">the data result</param>
    public delegate void DeleteMessagesDataResultEvent(DeleteMessagesDataResult dataResult);

    /// <summary>
    /// result data from deleting messages
    /// </summary>
    public class DeleteMessagesDataResult : OperationResult
    {
        /// <summary>
        /// Initializes a new instance of the DeleteMessagesDataResult class
        /// </summary>
        /// <param name="success">the success flag</param>
        /// <param name="messageIds">the ids of deleted messages</param>
        public DeleteMessagesDataResult(bool success, IList<int> messageIds)
        {
            this.Success = success;
            this.MessageIds = messageIds;
            this.Message = this.MakeMessage();
        }

        /// <summary>
        /// Initializes a new instance of the DeleteMessagesDataResult class with a message
        /// </summary>
        /// <param name="success">the success flag</param>
        /// <param name="message">the error message</param>
        /// <param name="error">the exception</param>
        public DeleteMessagesDataResult(bool success, string message, Exception error)
        {
            this.Success = success;
            this.Message = message;
            this.Error = error;
        }

        /// <summary>
        /// Gets the ids of deleted messages
        /// </summary>
        public IList<int> MessageIds { get; private set; }

        /// <summary>
        /// Make the operation message
        /// </summary>
        /// <returns>the message</returns>
        private string MakeMessage()
        {
            if (this.MessageIds.Count == 1)
            {
                return "Message deleted";
            }

            return string.Format(CultureInfo.CurrentUICulture, "{0} messages deleted", this.MessageIds.Count);
        }
    }
}
